function change_bugurl(tid) {
    var bugurl = document.getElementById("bugurl" + tid).value;
    ornot = window.confirm("BUG地址已修改，确认提交吗？")
    if (ornot == true) {
        $.ajax({
            url: "/Question/UpateQuestionBugUrl", //处理页面的路径
            data: {tid: tid, bugurl: bugurl},//要提交的数据是一个JSON
            type: "POST", //提交方式
            //TEXT字符串 JSON返回JSON XML返回XML
            success: function (data) { //回调函数 ,成功时返回的数据存在形参data里
                alert(data);
            }
        });
    }
    else alert("取消成功");
}

function AllQuestion() {

    $.ajaxSettings.async = false;
    $("#question_table").bootstrapTable('destroy');
    $('#question_table').bootstrapTable({
        url: "/Question/AllQuestion",
        method: 'post',
        contentType: 'application/x-www-form-urlencoded; charset=UTF-8',
        cache: false,
        //queryParams:queryParams,
        striped: true,
        pagination: true,
        sortable: true,
        sortOrder: "desc",
        sortName: 'posttime',
        sidePagination: 'client',
        pageSize: 10,
        pageNumber: 1,
        pageList: [10, 20, 50, 100, 200, 500],
        search: true,
        strictSearch: false,//是否全匹配
        showColumns: true,
        showRefresh: false,
        showExport: false,
        uniqueId: "uid",
        showToggle: false,
        cardView: false,
        // clickToSelect: true,
        //  showFooter:true,
        columns:
            [
                // {field: "checked", checkbox: true},
                {field: "tid", title: "反馈编号", align: "center", valign: "middle", sortable: "true"},
                {field: "useraccount", title: "用户名", align: "center", valign: "middle", sortable: "true"},
                {field: "username", title: "姓名", align: "center", valign: "middle", sortable: "true"},
                {field: "type", title: "类型", align: "center", valign: "middle", sortable: "true"},
                {field: "version", title: "版本", align: "center", valign: "middle", sortable: "true"},
                {field: "title", title: "主题", align: "center", valign: "middle", sortable: "true"},
                {
                    field: "content",
                    title: "内容",
                    width: 220,
                    align: "center",
                    valign: "middle",
                    sortable: "true",
                    formatter: AddContentText
                },
                {field: "posttime", title: "时间", align: "center", valign: "middle", sortable: "true"},
                {
                    field: "sendemail",
                    title: "问题跟进",
                    align: "center",
                    valign: "middle",
                    sortable: "true",
                    formatter: AddButton
                },
                {
                    field: "bugurl",
                    title: "BUG地址",
                    align: "center",
                    valign: "middle",
                    sortable: "true",
                    formatter: AddText
                },
                {
                    field: "status",
                    title: "处理状态",
                    align: "center",
                    valign: "middle",
                    sortable: "true",
                    formatter: AddSelect
                },
            ],
        onLoadSuccess: function (data) {
            if (data.code != null) {
                var code = data.code;
                var message = data.message;
                if (code == "400") {
                    alert(message);
                    window.parent.location.href = "/login.html";
                }
                else if (code == "401") {
                    alert(message);
                    window.location.href = "/error/error.html";
                }
            }
        }

    });

    function AddContentText(value, row, index) {
        return [
            '<textarea readonly="readonly">' + value + '</textarea>'
        ].join("");
    }

    function AddText(value, row, index) {
        if (value == null) value = " ";
        return [
            '<input TYPE="text"class="form-control" id="bugurl' + row.tid + '" style="width:95%;height: 25px" value="' + value + '" onchange="change_bugurl(' + row.tid + ')">'
        ].join("");
    }

    function AddButton(value, row, index) {
        return [
            '<button class="btn btn-default" style="width: auto;background-color: #9fcdff" onclick="prom(\'' + row.tid + '\')">Email</button>'

        ].join("");
    }

    function AddSelect(value, row, index) {
        return [
            '<select class="custom-select" id="type' + row.tid + '"onchange="TypeChange(' + row.tid + ')"> <option selected="selected">' + value + '</option><option value="待处理">待处理</option>' +
            '</option><option value="处理中">处理中</option>' +
            '</option><option value="已处理">已处理</option>'
        ].join("")
    }
}

function TypeChange(tid) {
    var status = document.getElementById("type" + tid).value;

    $.ajax({
        url: "/Question/UpateQuestion", //处理页面的路径
        data: {tid: tid, status: status},//要提交的数据是一个JSON
        type: "POST", //提交方式
        //TEXT字符串 JSON返回JSON XML返回XML
        success: function (data) { //回调函数 ,成功时返回的数据存在形参data里
            alert(data);
        }
    });
}

function prom(tid) {
    var email = prompt("请输入要发送的邮箱地址,多个邮箱用逗号分隔", ""); //将输入的内容赋给变量 name ，
    if (email)
        $.ajax({
            url: "/Question/SendEmail", //处理页面的路径
            data: {email: email, tid: tid},//要提交的数据是一个JSON
            type: "POST", //提交方式
            //TEXT字符串 JSON返回JSON XML返回XML
            success: function (data) { //回调函数 ,成功时返回的数据存在形参data里
                if (data.code != null) {
                    var code = data.code;
                    var message = data.message;
                    if (code == "400") {
                        alert(message);
                        window.parent.location.href = "/login.html";
                    }
                    else if (code == "401") {
                        alert(message);
                    }
                    return ;
                }
                alert(data);
            }
        });
    else return;
}